<script setup lang="ts">
import type { Component } from 'vue'

defineProps({
  icon: {
    type: Object as () => Component,
    required: false
  },
  name: {
    type: String,
    required: true
  },
  shortcutKeys: {
    type: String,
    required: false,
    default: ''
  },
  disable: {
    type: Boolean,
    required: false,
    default: false
  }
})
</script>

<template>
  <div class="contextmenu-item" :class="{ 'contextmenu-item-disable': disable }">
    <div class="menu-main">
      <div class="menu-icon">
        <el-icon :size="15">
          <Component v-if="icon" :is="icon" />
        </el-icon>
      </div>
      <div class="menu-name">
        {{ name }}
      </div>
    </div>
    <div class="shortcut-keys">
      {{ shortcutKeys }}
    </div>
  </div>
</template>

<style scoped lang="scss">
.contextmenu-item {
  display: flex;
  height: 30px;
  padding: 0 5px;
  margin: 1px 0;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  cursor: default;
  border-radius: 5px;

  .menu-main {
    display: flex;
    align-items: center;
    justify-content: flex-start;

    .menu-icon {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 25px;

      ::v-deep(.el-icon svg) {
        path {
          stroke-width: 3;
        }
      }

      span {
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }

    .menu-name {
      padding-left: 5px;
    }
  }

  .shortcut-keys {
    display: flex;
    align-items: center;
    color: var(--el-text-color-placeholder);
  }
}

.contextmenu-item:not(.contextmenu-item-disable):hover {
  background-color: var(--el-color-primary-light-9);
}

.contextmenu-item-disable {
  color: var(--el-text-color-disabled) !important;
}
</style>
